import torch


# 在当前工作目录写一个txt文本, 用于记录测试值信息
def write_things(va1, va2, va3, va4, va5, va6):
    with open('test.txt', 'w') as file:
        file.write(str(va1.item()) + '\n')
        file.write(str(va2.item()) + '\n')
        file.write(str(va3.item()) + '\n')
        file.write(str(va4.item()) + '\n')
        file.write(str(va5.item()) + '\n')
        file.write(str(va6.item()) + '\n')


# 在当前工作目录写一个txt文本, 用于记录当前学习率
def write_lr(va1):
    with open('lr.txt', 'w') as file:
        file.write('better lr ' + str(va1) + '\n')


# 读取当前工作目录的txt文本, 获得对应的测试指标值
def read_values_from_file():
    with open('test.txt', 'r') as file:
        lines = file.readlines()
        # 去除首尾的换行符或空格
        var1 = torch.tensor(float(lines[0].strip()))
        var2 = torch.tensor(float(lines[1].strip()))
        var3 = torch.tensor(float(lines[2].strip()))
        var4 = torch.tensor(float(lines[3].strip()))
        var5 = torch.tensor(float(lines[4].strip()))
        var6 = torch.tensor(float(lines[5].strip()))
        return var1, var2, var3, var4, var5, var6

